package com.yanqu.road.server.cmd.activity.springunionbanquet;

import com.yanqu.road.entity.activity.springunionbanquet.config.SpringUnionBanquetConfig;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SpringUnionBanquetProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.springunionbanquet.SpringUnionBanquetMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;

@Cmd(code = Protocol.S_SPRING_UNION_BANQUET_LIST, desc = "获取宴饮列表")
public class SpringUnionBanquetListCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        // 没有活动
        SpringUnionBanquetConfig config = SpringUnionBanquetMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        String unionUid = player.getUserInfo().getUnionUid();
        if(StringUtils.isNullOrEmpty(unionUid)){
            ret = GameErrorCode.E_UNION_NO_JOIN_UNION;
            return;
        }

        if(!SystemOpenMgr.systemOpen(player, eSystemId.SpringBanquet.getValue())){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }

        SpringUnionBanquetProto.CrossSpringUnionBanquetListReqMsg.Builder crossReq = SpringUnionBanquetProto.CrossSpringUnionBanquetListReqMsg.newBuilder();
        crossReq.setActivityId(config.getActivityId());
        crossReq.setUnionUid(unionUid);

        player.sendPacket(Protocol.C_SPRING_UNION_BANQUET_LIST, crossReq);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_SPRING_UNION_BANQUET_LIST, SpringUnionBanquetProto.SpringUnionBanquetListRespMsg.newBuilder().setRet(ret));
        }
    }
}
